from django.conf import settings
from django.http import Http404

from common.utils import get_ip_address

black_list = set(settings.BLACK_IP_LIST)


def simple_middleware(get_response):

    def middleware(request, *args, **kwargs):
        ip = get_ip_address(request)
        if ip in black_list:
            raise Http404()
        response = get_response(request, *args, **kwargs)

        return response

    return middleware
